﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Quartz;
using Quartz.Impl;

namespace Holytax.HaiErWS
{
    public class JobScheduler
    {
        ISchedulerFactory schedf = new StdSchedulerFactory();
        IScheduler scheduler = null;
        public JobScheduler()
        {
            scheduler = schedf.GetScheduler();
        }

        public void Start()
        {
            if (scheduler.IsStarted)
            {
                Continue();
                return;
            }
            scheduler.Start();

            IJobDetail demoJob = JobBuilder.Create<DownDate>().WithIdentity("作业名称2", "作业组").Build();
            ITrigger CronTrigger = TriggerBuilder.Create()
              .WithIdentity("触发器名称2", "触发器组")
              .WithCronSchedule("0/5 * * * * ? ")
              .Build();

            scheduler.ScheduleJob(demoJob, CronTrigger);
        }

        public void End()
        {
            if (scheduler.IsShutdown)
            {
                return;
            }
            scheduler.Shutdown(false);
        }

        public bool Continue()
        {
            scheduler.ResumeAll();
            return true;
        }

        public bool Pause()
        {
            scheduler.PauseAll();
            return true;
        }
    }
}
